<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');

/**
 * TYPOlight webCMS
 * Copyright (C) 2005-2009 Leo Feyer
 *
 * This program is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation, either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program. If not, please visit the Free
 * Software Foundation website at http://www.gnu.org/licenses/.
 *
 * PHP version 5
 * @copyright  include7 AG - Flavian Sierk 
 * @author     Flavian Sierk 
 * @package    donate 
 * @license    LGPL 
 * @filesource
 */



/**
 * Class ModuleDonate
 *
 * Front end content element "donate".
 * @copyright  include7 AG - Flavian Sierk 
 * @author     Flavian Sierk
 * @package    donate
 */

class ModuleDonate extends Module {

	protected $strTemplate = 'ce_donate';

	public function generate()
	{
		return parent::generate();
	}

	protected function compile()
	{

		$arrFields = array();
		$arrFields['amount'] = array
		(
			'name' => 'amount',
			'label' => str_replace('%1', $this->donate_currency_code, $GLOBALS['TL_LANG']['MSC']['donate_amount']),
			'inputType' => 'text',
			'value' => $this->donate_total,
			'eval' => array('maxlength'=>128, 'default' => 'foo')
		);
		foreach ($arrFields as $arrField)
		{
			$strClass = $GLOBALS['TL_FFL'][$arrField['inputType']];

			// Continue if the class is not defined
			if (!$this->classFileExists($strClass))
			{
				continue;
			}

			$arrField['eval']['required'] = $arrField['eval']['mandatory'];
			$objWidget = new $strClass($this->prepareForWidget($arrField, $arrField['name'], $arrField['value']));

			$arrWidgets[] = $objWidget;
		}

		$objPage = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")
								  ->limit(1)
								  ->execute($this->disclaimer_thanks);

		if ($objPage->numRows)
		{
			$strLink = $this->generateFrontendUrl($objPage->row());
		}
		$this->Template->return 	= $strLink;
		$this->Template->fields 	= $arrWidgets;
		$this->Template->amount 	= $GLOBALS['TL_LANG']['MSC']['donate_amount'];
		$this->Template->donate 	= $GLOBALS['TL_LANG']['MSC']['donate'];
		$this->Template->email 		= $this->donate_address;
		$this->Template->currency	= $this->donate_currency_code;
		$this->Template->item 		= $this->donate_message;
		$this->Template->ceID 		= $this->id;

		if($this->donate_javascript != '1'){
					$this->Template->noJavascript = true;
		}
	}
}